
*Sorting District and County Free Lunch and Special Ed Data for 1987*
import delimited using "ag13yr.txt", clear

gen str7 leaidstr=string(leaid,"%07.0f")
gen statefip=substr(leaidstr,1,2)
destring statefip, replace
drop leaidstr
rename leaid ncesid
keep if statefip==21
joinby ncesid using kydistcntycrosswalk.dta, unmatched(master)

save kydistccd19871998.dta, replace

foreach x in speced fle {
gen dist`x'share1987=`x'87/member87
egen dist`x'pctile1987=xtile(dist`x'share1987), nq(100)
egen dist`x'quartile1987=xtile(dist`x'share1987), nq(4)
}
order ncesid countyfip
label var distspecedshare1987 "Share of district students in special ed"
label var distfleshare1987 "Share of district students free lunch eligible"
label var distspecedpctile1987 "Percentile rank of distspecedshare1987"
label var distflepctile1987 "Percentile rank of distfleshare1987"
label var distspecedquartile1987 "Qaurtile rank of distspecedshare1987"
label var distflequartile1987 "Qaurtile rank of distfleshare1987"

sum distspecedshare1987 distfleshare1987

save distflespeced1987.dta, replace

use kydistccd19871998.dta

collapse (sum) member87 speced87 fle87, by(countyfip)

foreach x in speced fle {
gen cnty`x'share1987=`x'87/member87
egen cnty`x'pctile1987=xtile(cnty`x'share1987), nq(100)
egen cnty`x'quartile1987=xtile(cnty`x'share1987), nq(4)
}
keep countyfip cntyspecedshare1987 cntyfleshare1987 cntyspecedpctile1987 cntyflepctile1987 cntyspecedquartile1987 cntyflequartile1987
label var cntyspecedshare1987 "Share of county students in special ed"
label var cntyfleshare1987 "Share of county students free lunch eligible"
label var cntyspecedpctile1987 "Percentile rank of cntyspecedshare1987"
label var cntyflepctile1987 "Percentile rank of cntyfleshare1987"
label var cntyspecedquartile1987 "Quartile rank of cntyspecedshare1987"
label var cntyflequartile1987 "Quartile rank of cntyfleshare1987"

save cntyflespeced1987.dta, replace

clear





